#include <iostream>
#include <string>
using namespace std;

class Dog {
public:
  string name;
  int age;

  Dog() {}
  Dog(string name, int age) : name(name), age(age) {}

  void show() { cout << "dog name:" << name << ",age:" << age << endl; }
};

class Cat {
public:
  string name;
  int age;
  // 朋友属性
  Dog *myFriend;

  Cat() {}
  // 没有在类中提供复制构造函数，系统会自动提供一个
  Cat(const Cat &cat) {
    cout << "调用Cat的复制构造函数" << endl;
    this->name = cat.name; // 浅拷贝
    this->age = cat.age;   // 浅拷贝
    // this->myFriend=cat.myFriend; // 浅拷贝
    //  深拷贝,需要创建一个新的Dog对象
//     this->myFriend = 
//       new Dog(cat.myFriend->name, cat.myFriend->age);
  }

  void catchMouse() { cout << name << "抓到大老鼠！" << endl; }

  void eat() { cout << name << "吃小鱼干。。。" << endl; }
};

void fun(Cat c){
  cout<<c.name<<endl;                                          
}                                          

int main() {
  Cat c1;
  c1.name = "kitty1";
  c1.eat();
  //c1.catchMouse();
  //Cat *c2 = new Cat();
  //c2->name = "kitty2";
  // c3从c2复制, c3也指向Cat对象的内存
  //Cat *c3 = c2;
  //c3->name = "kitty3";
  //cout << "c2 name:" << c2->name << endl;
  //cout << "c3 name:" << c3->name << endl;

  // c4和c5, 希望将c4完整复制一份给c5
  //Cat c4;
  //c4.name = "kitty4";
  //c4.age = 1;
  //c4.myFriend = new Dog("旺财", 1);
  //cout << "c4 name:" << c4.name << ",age:" << c4.age << endl;
  //cout << "c4 friend name:" << c4.myFriend->name << ",age:" << c4.myFriend->age << endl;

  //cout << "创建c5对象:" << endl;
  //Cat c5 = c4; // 浅拷贝,会调用复制构造函数
  //cout << "c5 name:" << c5.name << ",age:" << c5.age << endl;
  //cout << "c5 friend name:" << c5.myFriend->name << ",age:" << c5.myFriend->age << endl;

  //c5.name = "kitty5";
  //c5.age = 2;
  //c5.myFriend->name = "小白";
  //c5.myFriend->age = 3;
  //cout << "修改c5后：" << endl;
  //cout << "c4 name:" << c4.name << ",age:" << c4.age << endl;
  //cout << "c4 friend name:" << c4.myFriend->name << ",age:" << c4.myFriend->age << endl;

  //cout << "c5 name:" << c5.name << ",age:" << c5.age << endl;
  //cout << "c5 friend name:" << c5.myFriend->name << ",age:" << c5.myFriend->age << endl;

  // 复制构造函数的执行时机
  cout<<"复制构造函数的执行时机...."<<endl;
//   Cat c6=c1;
//   Cat c7(c1);
//   Cat *c8=new Cat(c1);
  //Cat c9; // 创建独立对象,调用的是无参构造函数
  //c9=c1;  // 仅仅将c1对象的属性值赋值给c9

  // 调用的函数参数为值传递
  fun(c1);

  return 0;
}